package bfa.playlist_importer_exporter;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;

public class Helping {
	public static void createCachedFile(Context context, String fileName,
            String content) throws IOException {
	 
	    File cacheFile = new File(context.getCacheDir() + File.separator
	                + fileName);
	    cacheFile.createNewFile();
	 
	    FileOutputStream fos = new FileOutputStream(cacheFile);
	    OutputStreamWriter osw = new OutputStreamWriter(fos, "UTF8");
	    PrintWriter pw = new PrintWriter(osw);
	 
	    pw.println(content);
	 
	    pw.flush();
	    pw.close();
	}
	



	public static Intent getSendEmailIntent(Context context, String email,
            String subject, String body, String fileName) {
	 
	    final Intent emailIntent = new Intent(
	                android.content.Intent.ACTION_SEND);
	 
	    //Explicitly only use Gmail to send
	    //emailIntent.setClassName("com.google.android.gm","com.google.android.gm.ComposeActivityGmail");
	 
	    emailIntent.setType("plain/text");
	 
	    //Add the recipients
	    emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,
	                new String[] { email });
	 
	    emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
	 
	    emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, body);
	 
	    //Add the attachment by specifying a reference to our custom ContentProvider
	    //and the specific file of interest
	    emailIntent.putExtra(
	            Intent.EXTRA_STREAM,
	                Uri.parse("content://" + CachedFileProvider.AUTHORITY + "/"
	                        + fileName));
	 
	    return emailIntent;
	}
}

